package com.jie.eclipse.pan.preferences;

import org.eclipse.jface.preference.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbench;
import com.jie.eclipse.pan.Activator;

/**
 * This class represents a preference page that
 * is contributed to the Preferences dialog. By 
 * subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows
 * us to create a page that is small and knows how to 
 * save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They
 * are stored in the preference store that belongs to
 * the main plug-in class. That way, preferences can
 * be accessed directly via the preference store.
 */

public class PanPreferencePage
	extends FieldEditorPreferencePage
	implements IWorkbenchPreferencePage {

	public PanPreferencePage() {
		super(GRID);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
		setDescription("基本参数设置.");
	}
	
	/**
	 * Creates the field editors. Field editors are abstractions of
	 * the common GUI blocks needed to manipulate various types
	 * of preferences. Each field editor knows how to save and
	 * restore itself.
	 */
	public void createFieldEditors() {
		addField(new StringFieldEditor(PreferenceConstants.P_NAME, "用戶名:", getFieldEditorParent()));
		addField(new StringFieldEditor(PreferenceConstants.P_CUSTOM_NAME, "显示谁的自定义", getFieldEditorParent()));
		addField(new StringFieldEditor(PreferenceConstants.P_COMMON_COLUMN, "公共栏位", getFieldEditorParent()));
		addField(new StringFieldEditor(PreferenceConstants.P_DEFAULT_DATASOURCE, "默认数据源", getFieldEditorParent()));
		addField(new StringFieldEditor(PreferenceConstants.P_DEFAULT_SQL, "默认SQL", getFieldEditorParent()));
		
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DEFAULT_DATASOURCE, "Pan默认數據庫", getFieldEditorParent()));
		
		Group group1 = new Group(getFieldEditorParent(), SWT.NULL);
		group1.setText("Pan可用數據庫");
		group1.setLayout(new GridLayout(3, true));
		GridData gd=new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan=2;
		group1.setLayoutData(gd);
		
		Composite comp1 = new Composite(group1, SWT.NULL);
		comp1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		Composite comp2 = new Composite(group1, SWT.NULL);
		comp2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		Composite comp3 = new Composite(group1, SWT.NULL);
		comp3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_NAME1, "名稱",comp1));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_IP1, "IP", comp2));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_PWD1, "密碼", comp3));
		
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_NAME2, "名稱", comp1));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_IP2, "IP", comp2));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_PWD2, "密碼", comp3));
		
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_NAME3, "名稱", comp1));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_IP3, "IP", comp2));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_PWD3, "密碼", comp3));
		
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_NAME4, "名稱", comp1));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_IP4, "IP", comp2));
		addField(new StringFieldEditor(PreferenceConstants.P_PAN_DATASOURCE_PWD4, "密碼", comp3));
	}
	
	public void init(IWorkbench workbench) {
	}
	
}